/* Sentinel - IRC Statistical and Operator Services
** token.c - Tokenization routines
**
** Copyright W. Campbell and others.  See README for more details
** Some code Copyright: Jonathan George, Kai Seidler, ircd-hybrid Team,
**                      IRCnet IRCD developers.
**
** $Id: token.c 7 2010-02-01 19:17:42Z dubkat $
*/

#include <string.h>
#include "token.h"

int token_to_value(struct Token token_table[], char *token)
{
  int i;

  if ((token_table != NULL) && (token != NULL))
  {
    for (i = 0; token_table[i].text != NULL; i++)
    {
      if (strcasecmp(token_table[i].text, token) == 0)
      {
        return token_table[i].value;
      }
    }
    /* If no match... */
    return TOKEN_UNMATCHED;
  }

  /* Otherwise... */
  return TOKEN_ERROR;
}

const char *value_to_token(struct Token token_table[], int value)
{
  int i;

  if (token_table != NULL)
  {
    for (i = 0; token_table[i].text != NULL; i++)
    {
      if (token_table[i].value == value)
      {
        return token_table[i].text;
      }
    }
  }

  /* Otherwise... */
  return NULL;
}
